home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Returning a variable from system() function
- Date: 19 Jan 1996 17:27:37 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4dp5sp$c5d@umbc9.umbc.edu>
- References: <295336694wnr@iiga.demon.co.uk>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Pete Ryan <pete@iiga.demon.co.uk> wrote:
- |> I`ve just been experimenting with C on UNIX and have come across a
- |> problem!. There is a UNIX command called `find / -name gwire -print`
- |> which scans the UNIX drive for files/directories containing `gwire`.
- |> Anyway what I want to do is the following...
- |>
- |> #include <stdio.h>
- |> #include <stdlib.h>
- |> etc
-
- That 'etc' keyword gives me a syntax error, but you definitely need more
- includes even for this program since chdir() is a non-ANSI function.
-
- |> void main()
-
- You misspelled 'int main (void)'.
-
- |> {
- |> char tmp[];
-
- A non-determined size array?
-
- |> chdir("/usr2/willesden");
-
- See above...
-
- |> */ offending code below ;( */
- |> tmp = system("find . -name gwire");
- |>
- |> printf("%s",tmp");
-
-
- The problem is system() returns an int. If you want some kind of result
- then either use redirection to a file and then read that file or consult
- your reference manuals or an appropriate UNIX newsgroup for non-portable
- solutions.
-
- Oh and don't forget:
-
- return (0);
- |> }
- |>
- |> Therefore if I run `find . -name gwire -print` it returns all the
- |> directories containing `gwire`. However the code above does not
- |> work!!. Is it because `= system` returns an integer and not strings???
-
- You mean you know the problem and still asked? Yes, system() returns an
- int so assigning it to a string, which has no declared length, is
- going to give you problems to say the least.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-